//
//  WDArrivalServiceItemViewModel.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/8/4.
//

#import "WDArrivalServiceItemViewModel.h"

@implementation WDArrivalServiceItemViewModel

- (void)initialize
{
    [super initialize];
    
    _reqModel = [WDArrivalServiceReqModel new];
    
    self.pageId = 1;
    self.pageSize = 15;
    _reqModel.size = self.pageSize;
}

- (void)setupData {
//    WDArrivalServiceItemModel *model = [WDArrivalServiceItemModel new];
//    model.imgPath = @"https://youjia-image.cdn.bcebos.com/modelImage/3eaa1c34bae2808435e95131cd59bcc7/16957217327781266694.jpg@!1200_width";
//    model.plateNumber = @"鲁B325DE";
//    model.vehicleVin = @"LFVBA14B3Y3014078";
//    model.updateTime = @"2024-07-23 12:43:46";
//    model.modelName = @"小型车";
//    model.vehicleSalesValue = @"法系";
//    model.taskNo = @"LSNXQ1234567890NN";
//    model.appointmentTime = @"2024-02-03 12:32";
////    // 服务流程 0.待分派 1.待接车 2.检查中 3.维修中 4.待报单 5.已完成 6.已取消 7.已关闭
//    model.servFlow = 1;
//    [self.dataList addObject:model];
////    
//    model = [WDArrivalServiceItemModel new];
//    model.imgPath = @"https://youjia-image.cdn.bcebos.com/modelImage/3eaa1c34bae2808435e95131cd59bcc7/16957217327781266694.jpg@!1200_width";
//    model.plateNumber = @"鲁B325DE";
//    model.vehicleVin = @"LFVBA14B3Y3014078";
//    model.updateTime = @"2024-07-23 12:43:46";
//    model.modelName = @"小型车";
//    model.vehicleSalesValue = @"法系";
//    model.taskNo = @"LSNXQ1234567890NN";
//    model.appointmentTime = @"2024-02-03 12:32";
//    model.servFlow = 2;
//    [self.dataList addObject:model];
//    
//    model = [WDArrivalServiceItemModel new];
//    model.imgPath = @"https://youjia-image.cdn.bcebos.com/modelImage/3eaa1c34bae2808435e95131cd59bcc7/16957217327781266694.jpg@!1200_width";
//    model.plateNumber = @"鲁B325DE";
//    model.vehicleVin = @"LFVBA14B3Y3014078";
//    model.updateTime = @"2024-07-23 12:43:46";
//    model.modelName = @"小型车";
//    model.vehicleSalesValue = @"法系";
//    model.taskNo = @"LSNXQ1234567890NN";
//    model.appointmentTime = @"2024-02-03 12:32";
//    model.servFlow = 3;
//    [self.dataList addObject:model];
//    
//    model = [WDArrivalServiceItemModel new];
//    model.imgPath = @"https://youjia-image.cdn.bcebos.com/modelImage/3eaa1c34bae2808435e95131cd59bcc7/16957217327781266694.jpg@!1200_width";
//    model.plateNumber = @"鲁B325DE";
//    model.vehicleVin = @"LFVBA14B3Y3014078";
//    model.updateTime = @"2024-07-23 12:43:46";
//    model.modelName = @"小型车";
//    model.vehicleSalesValue = @"法系";
//    model.taskNo = @"LSNXQ1234567890NN";
//    model.appointmentTime = @"2024-02-03 12:32";
//    model.servFlow = 4;
//    [self.dataList addObject:model];
//    [self.dataList addObject:model];
//    [self.dataList addObject:model];
//    [self.dataList addObject:model];
//    [self.dataList addObject:model];
//    [self.dataList addObject:model];
//    [self.dataList addObject:model];
//    [self.dataList addObject:model];
//    [self.dataList addObject:model];
}

/// 请求数据
/// - Parameter completion: completion description
- (void)requestWithArrivalService:(RequestCompletionBlock)completion {
    _reqModel.current = self.pageId;
//    _reqModel.engineerId = @([EDSAppDelegateTool sharedInstance].userInfoModel.id);
    _reqModel.stationId = @([EDSAppDelegateTool sharedInstance].userInfoModel.stationId);
    @weakify(self);
    WDArrivalServiceRequest *request = [[WDArrivalServiceRequest alloc] initWithModel:self.reqModel];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        EDSRespondDataEntity *respond = request.responseModelObject;
        if (respond.code == EDS_NETWORK_SUCCESS) {
            if (self.pageId == 1) {
                [self.dataList  removeAllObjects];
            }
            NSArray *list = respond.data;
            [self.dataList addObjectsFromArray:list];
            if (list && list.count > 0) {
                self.pageId += 1;
            }
        }
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}


@end
